package com.wanglei.rdd.action

import org.apache.spark.{SparkConf, SparkContext}

object Spark03_aggregate {

  def main(args: Array[String]): Unit = {

    //
    val conf = new SparkConf().setMaster("local[2]").setAppName("map")
    val sc = new SparkContext(conf)


    val rdd = sc.makeRDD(List(
      1, 2, 3, 4
    ))


    // aggregate
    // aggregateByKey：初始值只会参与分区内计算
    // aggregate：初始值不仅会参与分区内计算，也会参与分区间计算
    val res = rdd.aggregate(0)(_ + _, _ + _)
    println(res)

    sc.stop()

  }

}


